package com.tianqingwl.gsystem.tags;

import com.tianqingwl.gsystem.resources.pojo.SysConfig;
import com.tianqingwl.gsystem.tags.processors.ContentInfoTagProcessor;
import com.tianqingwl.gsystem.tags.processors.ContentTypeTagProcessor;
import com.tianqingwl.gsystem.tags.processors.SysConfigTagProcessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.thymeleaf.dialect.AbstractProcessorDialect;
import org.thymeleaf.dialect.IExpressionObjectDialect;
import org.thymeleaf.expression.IExpressionObjectFactory;
import org.thymeleaf.processor.IProcessor;
import org.thymeleaf.standard.processor.StandardXmlNsTagProcessor;
import org.thymeleaf.templatemode.TemplateMode;

import java.util.HashSet;
import java.util.Set;

@Component
public class GSystemDialect extends AbstractProcessorDialect implements IExpressionObjectDialect {
    @Autowired
    private SysConfigTagProcessor sysConfigTagProcessor;
    @Autowired
    private ContentInfoTagProcessor contentInfoTagProcessor;
    @Autowired
    private ContentTypeTagProcessor contentTypeTagProcessor;

    public static final String NAME = "GSystem";
    public static final String PREFIX = "gs";
    public static final int PROCESSOR_PRECEDENCE = 1000;
    private IExpressionObjectFactory expressionObjectFactory = null;

    protected GSystemDialect() {
        super(NAME, PREFIX, PROCESSOR_PRECEDENCE);
    }


    @Override
    public Set<IProcessor> getProcessors(String dialectPrefix) {
        final Set<IProcessor> processors=new HashSet<>();
        processors.add(new StandardXmlNsTagProcessor(TemplateMode.HTML,PREFIX));
        processors.add(sysConfigTagProcessor);
        processors.add(contentInfoTagProcessor);
        processors.add(contentTypeTagProcessor);
        return processors;
    }


    @Override
    public IExpressionObjectFactory getExpressionObjectFactory() {
        if (expressionObjectFactory==null){
            expressionObjectFactory = new GSystemExpressionObjectFactory();
        }
        return expressionObjectFactory;
    }
}
